import request from '@/utils/request'

// 登录方法
export function login (phone, password) {
  const data = {
    phone,
    password
  }
  return request({
    url: '/api/v1/login',
    headers: {
      isToken: false,
      repeatSubmit: false
    },
    method: 'post',
    data: data
  })
}

// 注册方法
export function register (data) {
  return request({
    url: '/api/v1/register',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

//重设密码
export function resetPassword (data) {
  return request({
    url: '/api/v1/reset',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

// 获取用户详细信息
export function getInfo () {
  return request({
    url: '/api/v1/user/profile',
    method: 'get'
  })
}




// 退出方法
export function logout () {
  localStorage.removeItem('userInfo')
  return request({
    url: '/api/v1/logout',
    method: 'post'
  })

}

// 获取验证码
export function getCodeImg () {
  return request({
    url: '/api/v1/captcha',
    headers: {
      isToken: false
    },
    method: 'get',
    timeout: 20000
  })
}
export function getSmsCode (data) {
  return request({
    url: '/api/v1/sms_code',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data,
    timeout: 20000
  })
}

export function updateUserName (data) {
  return request({
    url: '/api/v1/user/username',
    method: 'put',
    data: data
  })
}
export function updateUserEmail (data) {
  return request({
    url: '/api/v1/user/email',
    method: 'put',
    data: data
  })
}


export function updateAvatar (data) {
  return request({
    url: '/api/v1/user/avatar',
    method: 'PUT',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    data: data
  })
}
